package ch.drshit.controller.listener;

import javax.swing.JProgressBar;

import ch.drshit.controller.Controller;
import ch.drshit.model.filter.BaseFilter;
import ch.drshit.model.filter.FilterListener;
import ch.drshit.model.picture.Options;
import ch.drshit.model.picture.Version;
import ch.drshit.view.swing.MyJComponent;

public class FilterController implements FilterListener {
	private Controller controller;

	public FilterController(Controller controller) {
		this.controller = controller;
	}

	@Override
	public void ServeOptions(Options o, BaseFilter f) {
		if (o.getHasOptions()) {
			o.useOptions(f);
		} else {
			f.startFilter(o);
		}
	}

	@Override
	public void filterStatusChanged(int prozent) {
		JProgressBar jpbar = this.getController().getView().getFrame().getJprogressbar();
		jpbar.setValue(prozent);
	}

	@Override
	public void result() {
		MyJComponent jcomp = this.getController().getView().getFrame()
				.getJcomponent();
		Version activeV = this.getController().getProject().getActiveVersion();
		jcomp.setBF(activeV.getBufferedImage());
		jcomp.repaint();
		JProgressBar jpbar = this.getController().getView().getFrame().getJprogressbar();
		jpbar.setValue(0);
	}

	public Controller getController() {
		return controller;
	}
}
